<!DOCTYPE html>


<html theme="dark" showBanner="true" hasBanner="false" > 
<link href="/blog/fontawesome/css/fontawesome.css" rel="stylesheet">
<link href="/blog/fontawesome/css/brands.css" rel="stylesheet">
<link href="/blog/fontawesome/css/solid.css" rel="stylesheet">
<script src="/blog/js/color.global.min.js" ></script>
<script src="/blog/js/load-settings.js" ></script>
<head>
  <meta charset="utf-8">
  
  
  

  
  <title>Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="preload" href="/blog/css/fonts/Roboto-Regular.ttf" as="font" type="font/ttf" crossorigin="anonymous">
  <link rel="preload" href="/blog/css/fonts/Roboto-Bold.ttf" as="font" type="font/ttf" crossorigin="anonymous">

  <meta name="description" content="一 Framebuffer数据结构 在DRM框架中，Framebuffer用于存储需要显示的内容，存储的信息包括：  需要显示的内容在内存区域的引用；  存储在内存中的帧的格式；  内存区域的激活区域（即将要显示的内容）；   DRM Framebuffer是一个虚拟的对象，它依赖于特定的实现。Framebuffer实现依赖于：  依赖于内存管理模块，比如GEM； 依赖于显示控制器的能力： 支持D">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo">
<meta property="og:url" content="https://zyly2033.gitee.io/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20framebuffer/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="一 Framebuffer数据结构 在DRM框架中，Framebuffer用于存储需要显示的内容，存储的信息包括：  需要显示的内容在内存区域的引用；  存储在内存中的帧的格式；  内存区域的激活区域（即将要显示的内容）；   DRM Framebuffer是一个虚拟的对象，它依赖于特定的实现。Framebuffer实现依赖于：  依赖于内存管理模块，比如GEM； 依赖于显示控制器的能力： 支持D">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://gitee.com/zyly2033/blog-pic/raw/master/202309021750538.png">
<meta property="og:image" content="https://gitee.com/zyly2033/blog-pic/raw/master/202309021817186.png">
<meta property="og:image" content="https://gitee.com/zyly2033/blog-pic/raw/master/202309031515578.svg">
<meta property="article:published_time" content="2023-09-11T12:23:16.198Z">
<meta property="article:modified_time" content="2023-09-03T14:35:53.235Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/zyly2033/blog-pic/raw/master/202309021750538.png">
  
    <link rel="alternate" href="/blog/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" media="(prefers-color-scheme: light)" href="/blog/images/favicon-light-32.png" sizes="32x32">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/blog/images/favicon-light-128.png" sizes="128x128">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/blog/images/favicon-light-180.png" sizes="180x180">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/blog/images/favicon-light-192.png" sizes="192x192">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/blog/images/favicon-dark-32.png" sizes="32x32">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/blog/images/favicon-dark-128.png" sizes="128x128">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/blog/images/favicon-dark-180.png" sizes="180x180">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/blog/images/favicon-dark-192.png" sizes="192x192">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  
   
  <div id="main-grid" class="shadow   ">
    <div id="nav" class=""  >
      <navbar id="navbar">
  <nav id="title-nav">
    <a href="/blog/">
      <div id="vivia-logo">
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
      </div>
      <div>Hexo </div>
    </a>
  </nav>
  <nav id="main-nav">
    
      <a class="main-nav-link" href="/blog/">Home</a>
    
      <a class="main-nav-link" href="/blog/archives">Archives</a>
    
      <a class="main-nav-link" href="/blog/about">About</a>
    
  </nav>
  <nav id="sub-nav">
    <a id="theme-btn" class="nav-icon">
      <span class="light-mode-icon"><svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M438.5-829.913v-48q0-17.452 11.963-29.476 11.964-12.024 29.326-12.024 17.363 0 29.537 12.024t12.174 29.476v48q0 17.452-11.963 29.476-11.964 12.024-29.326 12.024-17.363 0-29.537-12.024T438.5-829.913Zm0 747.826v-48q0-17.452 11.963-29.476 11.964-12.024 29.326-12.024 17.363 0 29.537 12.024t12.174 29.476v48q0 17.452-11.963 29.476-11.964 12.024-29.326 12.024-17.363 0-29.537-12.024T438.5-82.087ZM877.913-438.5h-48q-17.452 0-29.476-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537t29.476-12.174h48q17.452 0 29.476 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T877.913-438.5Zm-747.826 0h-48q-17.452 0-29.476-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537T82.087-521.5h48q17.452 0 29.476 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T130.087-438.5Zm660.174-290.87-34.239 32q-12.913 12.674-29.565 12.174-16.653-.5-29.327-13.174-12.674-12.673-12.554-28.826.12-16.152 12.794-28.826l33-35q12.913-12.674 30.454-12.674t30.163 12.847q12.709 12.846 12.328 30.826-.38 17.98-13.054 30.653ZM262.63-203.978l-32 34q-12.913 12.674-30.454 12.674t-30.163-12.847q-12.709-12.846-12.328-30.826.38-17.98 13.054-30.653l33.239-31q12.913-12.674 29.565-12.174 16.653.5 29.327 13.174 12.674 12.673 12.554 28.826-.12 16.152-12.794 28.826Zm466.74 33.239-32-33.239q-12.674-12.913-12.174-29.565.5-16.653 13.174-29.327 12.673-12.674 28.826-13.054 16.152-.38 28.826 12.294l35 33q12.674 12.913 12.674 30.454t-12.847 30.163q-12.846 12.709-30.826 12.328-17.98-.38-30.653-13.054ZM203.978-697.37l-34-33q-12.674-12.913-13.174-29.945-.5-17.033 12.174-29.707t31.326-13.293q18.653-.62 31.326 13.054l32 34.239q11.674 12.913 11.174 29.565-.5 16.653-13.174 29.327-12.673 12.674-28.826 12.554-16.152-.12-28.826-12.794ZM480-240q-100 0-170-70t-70-170q0-100 70-170t170-70q100 0 170 70t70 170q0 100-70 170t-170 70Zm-.247-82q65.703 0 111.475-46.272Q637-414.544 637-480.247t-45.525-111.228Q545.95-637 480.247-637t-111.475 45.525Q323-545.95 323-480.247t45.525 111.975Q414.05-322 479.753-322ZM481-481Z"/></svg></span>
      <span class="dark-mode-icon"><svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M480.239-116.413q-152.63 0-258.228-105.478Q116.413-327.37 116.413-480q0-130.935 77.739-227.435t206.304-125.043q43.022-9.631 63.87 10.869t3.478 62.805q-8.891 22.043-14.315 44.463-5.424 22.42-5.424 46.689 0 91.694 64.326 155.879 64.325 64.186 156.218 64.186 24.369 0 46.978-4.946 22.609-4.945 44.413-14.076 42.826-17.369 62.967 1.142 20.142 18.511 10.511 61.054Q807.174-280 712.63-198.206q-94.543 81.793-232.391 81.793Zm0-95q79.783 0 143.337-40.217 63.554-40.218 95.793-108.283-15.608 4.044-31.097 5.326-15.49 1.283-31.859.805-123.706-4.066-210.777-90.539-87.071-86.473-91.614-212.092-.24-16.369.923-31.978 1.164-15.609 5.446-30.978-67.826 32.478-108.282 96.152Q211.652-559.543 211.652-480q0 111.929 78.329 190.258 78.329 78.329 190.258 78.329ZM466.13-465.891Z"/></svg></span>
    </a>
    
      <a id="nav-rss-link" class="nav-icon mobile-hide" href="/blog/atom.xml" title="RSS Feed">
        <svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M198-120q-25.846 0-44.23-18.384-18.384-18.385-18.384-44.23 0-25.846 18.384-44.23 18.384-18.385 44.23-18.385 25.846 0 44.23 18.385 18.384 18.384 18.384 44.23 0 25.845-18.384 44.23Q223.846-120 198-120Zm538.385 0q-18.846 0-32.923-13.769-14.076-13.769-15.922-33.23-8.692-100.616-51.077-188.654-42.385-88.039-109.885-155.539-67.5-67.501-155.539-109.885Q283-663.462 182.385-672.154q-19.461-1.846-33.23-16.23-13.769-14.385-13.769-33.846t14.076-32.922q14.077-13.461 32.923-12.23 120.076 8.692 226.038 58.768 105.961 50.077 185.73 129.846 79.769 79.769 129.846 185.731 50.077 105.961 58.769 226.038 1.231 18.846-12.538 32.922Q756.461-120 736.385-120Zm-252 0q-18.231 0-32.423-13.461t-18.653-33.538Q418.155-264.23 348.886-333.5q-69.27-69.27-166.501-84.423-20.077-4.462-33.538-18.961-13.461-14.5-13.461-33.346 0-19.076 13.884-33.23 13.884-14.153 33.115-10.922 136.769 15.384 234.384 112.999 97.615 97.615 112.999 234.384 3.231 19.23-10.538 33.115Q505.461-120 484.385-120Z"/></svg>
      </a>
    
    <div id="nav-menu-btn" class="nav-icon">
      <svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M177.37-252.282q-17.453 0-29.477-11.964-12.024-11.963-12.024-29.326t12.024-29.537q12.024-12.174 29.477-12.174h605.26q17.453 0 29.477 11.964 12.024 11.963 12.024 29.326t-12.024 29.537q-12.024 12.174-29.477 12.174H177.37Zm0-186.218q-17.453 0-29.477-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537T177.37-521.5h605.26q17.453 0 29.477 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T782.63-438.5H177.37Zm0-186.217q-17.453 0-29.477-11.964-12.024-11.963-12.024-29.326t12.024-29.537q12.024-12.174 29.477-12.174h605.26q17.453 0 29.477 11.964 12.024 11.963 12.024 29.326t-12.024 29.537q-12.024 12.174-29.477 12.174H177.37Z"/></svg>
    </div>
  </nav>
</navbar>
<div id="nav-dropdown" class="hidden">
  <div id="dropdown-link-list">
    
      <a class="nav-dropdown-link" href="/blog/">Home</a>
    
      <a class="nav-dropdown-link" href="/blog/archives">Archives</a>
    
      <a class="nav-dropdown-link" href="/blog/about">About</a>
    
    
      <a class="nav-dropdown-link" href="/blog/atom.xml" title="RSS Feed">RSS</a>
     
    </div>
</div>
<script>
  let dropdownBtn = document.getElementById("nav-menu-btn");
  let dropdownEle = document.getElementById("nav-dropdown");
  dropdownBtn.onclick = function() {
    dropdownEle.classList.toggle("hidden");
  }
</script>
    </div>
    <div id="sidebar-wrapper">
      <sidebar id="sidebar">
  
    <div class="widget-wrap">
  <div class="info-card">
    <div class="avatar">
      
      <div class="img-dim"></div>
    </div>
    <div class="info">
      <div class="username">Your Name </div>
      <div class="dot"></div>
      <div class="subtitle">This is the subtitle </div>
      <div class="link-list">
        
          <a class="link-btn" target="_blank" rel="noopener" href="https://twitter.com" title="Twitter"><i class="fa-brands fa-twitter"></i></a>
        
          <a class="link-btn" target="_blank" rel="noopener" href="https://store.steampowered.com" title="Steam"><i class="fa-brands fa-steam"></i></a>
        
          <a class="link-btn" target="_blank" rel="noopener" href="https://github.com" title="GitHub"><i class="fa-brands fa-github"></i></a>
         
      </div>  
    </div>
  </div>
</div>

  
  <div class="sticky">
    
      



    
      

    
      
  <div class="widget-wrap">
    <div class="widget">
      <h3 class="widget-title">Archives</h3>
      
      
        <a class="archive-link" href="/blog/archives/2023/09 ">
          September 2023 
          <div class="archive-count">8 </div>
        </a>
      
    </div>
  </div>


    
      
  <div class="widget-wrap">
    <div class="widget">
      <h3 class="widget-title">Recent Posts</h3>
      <ul>
        
          <a class="recent-link" href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F/" title="" >
            <div class="recent-link-text">
              (no title)
            </div>
          </a>
        
          <a class="recent-link" href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%E5%AD%90%E7%B3%BB%E7%BB%9F/" title="" >
            <div class="recent-link-text">
              (no title)
            </div>
          </a>
        
          <a class="recent-link" href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20plane/" title="" >
            <div class="recent-link-text">
              (no title)
            </div>
          </a>
        
          <a class="recent-link" href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20framebuffer/" title="" >
            <div class="recent-link-text">
              (no title)
            </div>
          </a>
        
          <a class="recent-link" href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20crtc/" title="" >
            <div class="recent-link-text">
              (no title)
            </div>
          </a>
        
      </ul>
    </div>
  </div>

    
  </div>
</sidebar>
    </div>
    <div id="content-body">
       

<article id="post-rk3399/Rockchip RK3399 - DRM framebuffer" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  
    
   
  <div class="article-inner">
    <div class="article-main">
      <header class="article-header">
        
<div class="main-title-bar">
  <div class="main-title-dot"></div>
  
    
      <h1 class="p-name article-title" itemprop="headline name">
        Untitled
      </h1>
    
  
</div>

        <div class='meta-info-bar'>
          <div class="meta-info">
  <time class="dt-published" datetime="2023-09-11T12:23:16.198Z" itemprop="datePublished">2023-09-11</time>
</div>
          <div class="need-seperator meta-info">
            <div class="meta-cate-flex">
  
    Uncategorized 
   
</div>
  
          </div>
          <div class="wordcount need-seperator meta-info">
            2.8k words 
          </div>
        </div>
        
      </header>
      <div class="e-content article-entry" itemprop="articleBody">
        
          <h3 id="一-Framebuffer数据结构"><a href="#一-Framebuffer数据结构" class="headerlink" title="一 Framebuffer数据结构"></a>一 Framebuffer数据结构</h3><p><img src="https://gitee.com/zyly2033/blog-pic/raw/master/202309021750538.png"></p>
<p>在DRM框架中，Framebuffer用于存储需要显示的内容，存储的信息包括：</p>
<ul>
<li><p>需要显示的内容在内存区域的引用；</p>
</li>
<li><p>存储在内存中的帧的格式；</p>
</li>
<li><p>内存区域的激活区域（即将要显示的内容）；</p>
</li>
</ul>
<p>DRM Framebuffer是一个虚拟的对象，它依赖于特定的实现。Framebuffer实现依赖于：</p>
<ul>
<li>依赖于内存管理模块，比如GEM；</li>
<li>依赖于显示控制器的能力：<ul>
<li>支持DMA传输类型（可以是连续内存或者Scatter Gather）；</li>
<li>IOMMU;</li>
</ul>
</li>
</ul>
<h4 id="1-1-struct-drm-framebuffer"><a href="#1-1-struct-drm-framebuffer" class="headerlink" title="1.1 struct drm_framebuffer"></a>1.1 struct drm_framebuffer</h4><p>linux内核使用struct drm_framebuffer表示一个帧缓冲，包括像素格式、分辨率和显存地址等信息。定义在include&#x2F;drm&#x2F;drm_framebuffer.h；</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * struct drm_framebuffer - frame buffer object</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * Note that the fb is refcounted for the benefit of driver internals,</span></span><br><span class="line"><span class="comment"> * for example some hw, disabling a CRTC/plane is asynchronous, and</span></span><br><span class="line"><span class="comment"> * scanout does not actually complete until the next vblank.  So some</span></span><br><span class="line"><span class="comment"> * cleanup (like releasing the reference(s) on the backing GEM bo(s))</span></span><br><span class="line"><span class="comment"> * should be deferred.  In cases like this, the driver would like to</span></span><br><span class="line"><span class="comment"> * hold a ref to the fb even though it has already been removed from</span></span><br><span class="line"><span class="comment"> * userspace perspective. See drm_framebuffer_get() and</span></span><br><span class="line"><span class="comment"> * drm_framebuffer_put().</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * The refcount is stored inside the mode object @base.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">drm_framebuffer</span> &#123;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @dev: DRM device this framebuffer belongs to</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">drm_device</span> *<span class="title">dev</span>;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @head: Place on the &amp;drm_mode_config.fb_list, access protected by</span></span><br><span class="line"><span class="comment">         * &amp;drm_mode_config.fb_lock.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">list_head</span> <span class="title">head</span>;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @base: base modeset object structure, contains the reference count.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">drm_mode_object</span> <span class="title">base</span>;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @comm: Name of the process allocating the fb, used for fb dumping.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">char</span> comm[TASK_COMM_LEN];</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @format: framebuffer format information</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">const</span> <span class="class"><span class="keyword">struct</span> <span class="title">drm_format_info</span> *<span class="title">format</span>;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @funcs: framebuffer vfunc table</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">const</span> <span class="class"><span class="keyword">struct</span> <span class="title">drm_framebuffer_funcs</span> *<span class="title">funcs</span>;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @pitches: Line stride per buffer. For userspace created object this</span></span><br><span class="line"><span class="comment">         * is copied from drm_mode_fb_cmd2.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">unsigned</span> <span class="type">int</span> pitches[DRM_FORMAT_MAX_PLANES];</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @offsets: Offset from buffer start to the actual pixel data in bytes,</span></span><br><span class="line"><span class="comment">         * per buffer. For userspace created object this is copied from</span></span><br><span class="line"><span class="comment">         * drm_mode_fb_cmd2.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Note that this is a linear offset and does not take into account</span></span><br><span class="line"><span class="comment">         * tiling or buffer layout per @modifier. It is meant to be used when</span></span><br><span class="line"><span class="comment">         * the actual pixel data for this framebuffer plane starts at an offset,</span></span><br><span class="line"><span class="comment">         * e.g. when multiple planes are allocated within the same backing</span></span><br><span class="line"><span class="comment">         * storage buffer object. For tiled layouts this generally means its</span></span><br><span class="line"><span class="comment">         * @offsets must at least be tile-size aligned, but hardware often has</span></span><br><span class="line"><span class="comment">         * stricter requirements.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * This should not be used to specifiy x/y pixel offsets into the buffer</span></span><br><span class="line"><span class="comment">         * data (even for linear buffers). Specifying an x/y pixel offset is</span></span><br><span class="line"><span class="comment">         * instead done through the source rectangle in &amp;struct drm_plane_state.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">unsigned</span> <span class="type">int</span> offsets[DRM_FORMAT_MAX_PLANES];</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @modifier: Data layout modifier. This is used to describe</span></span><br><span class="line"><span class="comment">         * tiling, or also special layouts (like compression) of auxiliary</span></span><br><span class="line"><span class="comment">         * buffers. For userspace created object this is copied from</span></span><br><span class="line"><span class="comment">         * drm_mode_fb_cmd2.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">uint64_t</span> modifier;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @width: Logical width of the visible area of the framebuffer, in</span></span><br><span class="line"><span class="comment">         * pixels.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">unsigned</span> <span class="type">int</span> width;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @height: Logical height of the visible area of the framebuffer, in</span></span><br><span class="line"><span class="comment">         * pixels.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">unsigned</span> <span class="type">int</span> height;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @flags: Framebuffer flags like DRM_MODE_FB_INTERLACED or</span></span><br><span class="line"><span class="comment">         * DRM_MODE_FB_MODIFIERS.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">int</span> flags;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @hot_x: X coordinate of the cursor hotspot. Used by the legacy cursor</span></span><br><span class="line"><span class="comment">         * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR</span></span><br><span class="line"><span class="comment">         * universal plane.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">int</span> hot_x;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @hot_y: Y coordinate of the cursor hotspot. Used by the legacy cursor</span></span><br><span class="line"><span class="comment">         * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR</span></span><br><span class="line"><span class="comment">         * universal plane.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">int</span> hot_y;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @filp_head: Placed on &amp;drm_file.fbs, protected by &amp;drm_file.fbs_lock.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">list_head</span> <span class="title">filp_head</span>;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @obj: GEM objects backing the framebuffer, one per plane (optional).</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * This is used by the GEM framebuffer helpers, see e.g.</span></span><br><span class="line"><span class="comment">         * drm_gem_fb_create().</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">drm_gem_object</span> *<span class="title">obj</span>[<span class="title">DRM_FORMAT_MAX_PLANES</span>];</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>该结构体包括以下成员：</p>
<ul>
<li>dev：该framebuffer所属的DRM设备；</li>
<li>head：链表节点，用于将当前节点添加到drm_mode_config.fb_list链表；</li>
<li>base：struct drm_mode_object；</li>
<li>comn：char数组，数组长度为32，用于存放分配该fb的进程的名字；</li>
<li>format：帧缓冲的格式信息；</li>
<li>funcs：帧缓冲的函数表；</li>
<li>pitches：无符号int数组，数组长度为4，存放每个plane缓冲区的行跨度（以字节为单位）；</li>
<li>offsets：无符号int数组，数组长度为4，存放每个plane缓冲区中实际像素数据相对于缓冲区起始处的偏移量（以字节为单位）；</li>
<li>modifier：数据布局修饰符，用于描述缓冲区的平铺或特殊布局；</li>
<li>width：帧缓冲可见区域的逻辑宽度（以像素为单位）；</li>
<li>height：帧缓冲可见区域的逻辑高度（以像素为单位）；</li>
<li>flags：帧缓冲的标志，例如DRM_MODE_FB_INTERLACED或DRM_MODE_FB_MODIFIERS；</li>
<li>hot_x：光标热点的X坐标， Used by the legacy cursor IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR universal plane；</li>
<li>hot_y：光标热点的Y坐标，Used by the legacy cursor IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR universal plane；</li>
<li>filp_head：链表节点，用于将该帧缓冲对象加入到drm_file结构的fbs链表中，访问此链表需要使用fbs_lock进行保护；</li>
<li>obj：struct drm_gem_object类型指针数组，数组长度为4，备份帧缓冲的GEM对象，每个plane一个对象；</li>
</ul>
<p>struct drm_framebuffer主要元素的展示如下图所示，其中Memory Region表示帧缓冲区，Dsisplayed Area表示实际显示区域，图中棕色区域表示实际像素数据相对于帧缓冲区起始处的偏移量；</p>
<p><img src="https://gitee.com/zyly2033/blog-pic/raw/master/202309021817186.png"></p>
<p>这里需要介绍一下pitches、offsets为啥是个数组，数组的长度为DRM_FORMAT_MAX_PLANES，通过这个宏我们大概可以了解到每种DRM格式应该包含多个plane，因此数组元素的值依次对应每个plane；</p>
<h4 id="1-2-struct-drm-format-info"><a href="#1-2-struct-drm-format-info" class="headerlink" title="1.2 struct drm_format_info"></a>1.2 struct drm_format_info</h4><p>linux内核使用struct drm_format_info表示DRM格式信息（更准确说应该是帧缓冲数据格式），定义在include&#x2F;drm&#x2F;drm_fourcc.h;</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * struct drm_format_info - information about a DRM format</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">drm_format_info</span> &#123;</span></span><br><span class="line">        <span class="comment">/** @format: 4CC format identifier (DRM_FORMAT_*) */</span></span><br><span class="line">        u32 format;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @depth:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Color depth (number of bits per pixel excluding padding bits),</span></span><br><span class="line"><span class="comment">         * valid for a subset of RGB formats only. This is a legacy field, do</span></span><br><span class="line"><span class="comment">         * not use in new code and set to 0 for new formats.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        u8 depth;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/** @num_planes: Number of color planes (1 to 3) */</span></span><br><span class="line">        u8 num_planes;</span><br><span class="line"></span><br><span class="line">        <span class="class"><span class="keyword">union</span> &#123;</span></span><br><span class="line">                <span class="comment">/**</span></span><br><span class="line"><span class="comment">                 * @cpp:</span></span><br><span class="line"><span class="comment">                 *</span></span><br><span class="line"><span class="comment">                 * Number of bytes per pixel (per plane), this is aliased with</span></span><br><span class="line"><span class="comment">                 * @char_per_block. It is deprecated in favour of using the</span></span><br><span class="line"><span class="comment">                 * triplet @char_per_block, @block_w, @block_h for better</span></span><br><span class="line"><span class="comment">                 * describing the pixel format.</span></span><br><span class="line"><span class="comment">                 */</span></span><br><span class="line">                u8 cpp[DRM_FORMAT_MAX_PLANES];</span><br><span class="line"></span><br><span class="line">                <span class="comment">/**</span></span><br><span class="line"><span class="comment">                 * @char_per_block:</span></span><br><span class="line"><span class="comment">                 *</span></span><br><span class="line"><span class="comment">                 * Number of bytes per block (per plane), where blocks are</span></span><br><span class="line"><span class="comment">                 * defined as a rectangle of pixels which are stored next to</span></span><br><span class="line"><span class="comment">                 * each other in a byte aligned memory region. Together with</span></span><br><span class="line"><span class="comment">                 * @block_w and @block_h this is used to properly describe tiles</span></span><br><span class="line"><span class="comment">                 * in tiled formats or to describe groups of pixels in packed</span></span><br><span class="line"><span class="comment">                 * formats for which the memory needed for a single pixel is not</span></span><br><span class="line"><span class="comment">                 * byte aligned.</span></span><br><span class="line"><span class="comment">                 *</span></span><br><span class="line"><span class="comment">                 * @cpp has been kept for historical reasons because there are</span></span><br><span class="line"><span class="comment">                 * a lot of places in drivers where it&#x27;s used. In drm core for</span></span><br><span class="line"><span class="comment">                 * generic code paths the preferred way is to use</span></span><br><span class="line"><span class="comment">                 * @char_per_block, drm_format_info_block_width() and</span></span><br><span class="line"><span class="comment">                 * drm_format_info_block_height() which allows handling both</span></span><br><span class="line"><span class="comment">                 * block and non-block formats in the same way.</span></span><br><span class="line"><span class="comment">                 *</span></span><br><span class="line"><span class="comment">                 * For formats that are intended to be used only with non-linear</span></span><br><span class="line"><span class="comment">                 * modifiers both @cpp and @char_per_block must be 0 in the</span></span><br><span class="line"><span class="comment">                 * generic format table. Drivers could supply accurate</span></span><br><span class="line"><span class="comment">                 * information from their drm_mode_config.get_format_info hook</span></span><br><span class="line"><span class="comment">                 * if they want the core to be validating the pitch.</span></span><br><span class="line"><span class="comment">                 */</span></span><br><span class="line">                u8 char_per_block[DRM_FORMAT_MAX_PLANES];</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @block_w:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Block width in pixels, this is intended to be accessed through</span></span><br><span class="line"><span class="comment">         * drm_format_info_block_width()</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        u8 block_w[DRM_FORMAT_MAX_PLANES];</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @block_h:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Block height in pixels, this is intended to be accessed through</span></span><br><span class="line"><span class="comment">         * drm_format_info_block_height()</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        u8 block_h[DRM_FORMAT_MAX_PLANES];</span><br><span class="line"></span><br><span class="line">        <span class="comment">/** @hsub: Horizontal chroma subsampling factor */</span></span><br><span class="line">        u8 hsub;</span><br><span class="line">        <span class="comment">/** @vsub: Vertical chroma subsampling factor */</span></span><br><span class="line">        u8 vsub;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/** @has_alpha: Does the format embeds an alpha component? */</span></span><br><span class="line">        <span class="type">bool</span> has_alpha;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/** @is_yuv: Is it a YUV format? */</span></span><br><span class="line">        <span class="type">bool</span> is_yuv;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/** @is_color_indexed: Is it a color-indexed format? */</span></span><br><span class="line">        <span class="type">bool</span> is_color_indexed;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>它包括以下字段：</p>
<ul>
<li>format：4CC格式标识符（DRM_FORMAT_*）;</li>
<li>depth：颜色深度（每像素的位数，不包括填充位），仅适用于部分RGB格式。这是一个过时字段，在新代码中不要使用，并且对于新格式设置为0。</li>
<li>num_planes：color plane数量（1到3）。</li>
<li>cpp：数组长度为4，依次存储每个plane每像素的字节数，与char_per_block具有别名。对于更好地描述像素格式，已弃用此字段，推荐使用三元组char_per_block、block_w、block_h；</li>
<li>char_per_block：数组长度为4，依次存储每个块的字节数，块被定义为以字节对齐的内存区域中相邻存储的像素矩形。与block_w和block_h一起使用，可以正确描述平铺格式中的图块，或者对于单个像素所需的字节对齐的打包格式中的像素组；</li>
<li>block_w：数组长度为4，依次存储块宽度（以像素为单位），应通过drm_format_info_block_width()访问；</li>
<li>block_h：数组长度为4，依次存储块高度（以像素为单位），应通过drm_format_info_block_height()访问；</li>
<li>hsub：水平色度亚采样因子；</li>
<li>vsub：垂直色度亚采样因子；</li>
<li>has_alpha：格式是否包含Alpha分量；</li>
<li>is_yuv：格式是否为YUV格式；</li>
<li>is_color_indexed：格式是否为索引颜色格式；</li>
</ul>
<h5 id="1-2-1-FOURCC"><a href="#1-2-1-FOURCC" class="headerlink" title="1.2.1  FOURCC"></a>1.2.1  FOURCC</h5><p>什么是4CC格式（或者说FOURCC format ）？它是一种用于标识数据格式的约定，每个FOURCC编码由4个ASCII字符组成，通过表示特定类型的数据格式、编码或标记。</p>
<p>FOURCC代码最初由Microsoft引入并广泛应用于多媒体和图像处理领域。它们通常用于标识和区分不同的文件格式、视频编解码器、像素格式、音频格式等。</p>
<p>在计算机图形中，FOURCC代码常用于指定像素格式，例如在视频编码和解码中。通过使用FOURCC编码，可以快速识别和解释特定的数据格式，以便进行适当的处理和解码。</p>
<p>需要注意的是，FOURCC代码只是一种标识符号，代表了特定的格式或类型，具体的实现和处理方式仍需根据具体的应用和上下文来确定。</p>
<p>DRM支持的FOURCC格式定义在include&#x2F;drm&#x2F;drm_fourcc.h：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * DRM_FORMAT_MAX_PLANES - maximum number of planes a DRM format can have</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> DRM_FORMAT_MAX_PLANES   4u  <span class="comment">// DRM格式最多包含的plane数量</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * DRM formats are little endian.  Define host endian variants for the</span></span><br><span class="line"><span class="comment"> * most common formats here, to reduce the #ifdefs needed in drivers.</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * Note that the DRM_FORMAT_BIG_ENDIAN flag should only be used in</span></span><br><span class="line"><span class="comment"> * case the format can&#x27;t be specified otherwise, so we don&#x27;t end up</span></span><br><span class="line"><span class="comment"> * with two values describing the same format.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> __BIG_ENDIAN</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_XRGB1555     (DRM_FORMAT_XRGB1555         |    \</span></span><br><span class="line"><span class="meta">                                       DRM_FORMAT_BIG_ENDIAN)</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_RGB565       (DRM_FORMAT_RGB565           |    \</span></span><br><span class="line"><span class="meta">                                       DRM_FORMAT_BIG_ENDIAN)</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_XRGB8888     DRM_FORMAT_BGRX8888</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_ARGB8888     DRM_FORMAT_BGRA8888</span></span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_XRGB1555     DRM_FORMAT_XRGB1555</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_RGB565       DRM_FORMAT_RGB565</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_XRGB8888     DRM_FORMAT_XRGB8888</span></span><br><span class="line"><span class="meta"># <span class="keyword">define</span> DRM_FORMAT_HOST_ARGB8888     DRM_FORMAT_ARGB8888</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<p>RGB是颜色的编码格式，它代表红色（R）、绿色（G）和蓝色（B）三个颜色通道。</p>
<p>在RGB编码中，每个像素使用一个包含三个数字值的元组来表示颜色。这三个值分别表示红色、绿色和蓝色的亮度或强度。每个值的范围是从0到255，其中0表示没有该颜色的亮度，而255表示最高强度或亮度。</p>
<p>ARGB是在RGB编码的基础上增加了一个额外的通道——Alpha通道。Alpha通道用于表示像素的透明度，即图像中该像素的不透明程度。Alpha通道的取值范围也是0到255，其中0表示完全透明，255表示完全不透明。</p>
<p>XRGB是指在RGB编码中，其中一个字节（8位）被保留但未使用。通常这个保留位是填充0，因此它不影响颜色的表示。这种编码方式常用于某些特定的图形处理操作和计算中，可以提高效率和内存利用率。</p>
<h4 id="1-3-struct-drm-framebuffer-funcs"><a href="#1-3-struct-drm-framebuffer-funcs" class="headerlink" title="1.3 struct drm_framebuffer_funcs"></a>1.3 struct drm_framebuffer_funcs</h4><p>linux内核使用struct drm_framebuffer_funcs表示帧缓冲区的基本操作，定义在include&#x2F;drm&#x2F;drm_framebuffer.h：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * struct drm_framebuffer_funcs - framebuffer hooks</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">drm_framebuffer_funcs</span> &#123;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @destroy:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Clean up framebuffer resources, specifically also unreference the</span></span><br><span class="line"><span class="comment">         * backing storage. The core guarantees to call this function for every</span></span><br><span class="line"><span class="comment">         * framebuffer successfully created by calling</span></span><br><span class="line"><span class="comment">         * &amp;drm_mode_config_funcs.fb_create. Drivers must also call</span></span><br><span class="line"><span class="comment">         * drm_framebuffer_cleanup() to release DRM core resources for this</span></span><br><span class="line"><span class="comment">         * framebuffer.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">void</span> (*destroy)(<span class="keyword">struct</span> drm_framebuffer *framebuffer);</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @create_handle:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Create a buffer handle in the driver-specific buffer manager (either</span></span><br><span class="line"><span class="comment">         * GEM or TTM) valid for the passed-in &amp;struct drm_file. This is used by</span></span><br><span class="line"><span class="comment">         * the core to implement the GETFB IOCTL, which returns (for</span></span><br><span class="line"><span class="comment">         * sufficiently priviledged user) also a native buffer handle. This can</span></span><br><span class="line"><span class="comment">         * be used for seamless transitions between modesetting clients by</span></span><br><span class="line"><span class="comment">         * copying the current screen contents to a private buffer and blending</span></span><br><span class="line"><span class="comment">         * between that and the new contents.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * GEM based drivers should call drm_gem_handle_create() to create the</span></span><br><span class="line"><span class="comment">         * handle.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * RETURNS:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * 0 on success or a negative error code on failure.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">int</span> (*create_handle)(<span class="keyword">struct</span> drm_framebuffer *fb,</span><br><span class="line">                             <span class="keyword">struct</span> drm_file *file_priv,</span><br><span class="line">                             <span class="type">unsigned</span> <span class="type">int</span> *handle);</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * @dirty:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Optional callback for the dirty fb IOCTL.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Userspace can notify the driver via this callback that an area of the</span></span><br><span class="line"><span class="comment">         * framebuffer has changed and should be flushed to the display</span></span><br><span class="line"><span class="comment">         * hardware. This can also be used internally, e.g. by the fbdev</span></span><br><span class="line"><span class="comment">         * emulation, though that&#x27;s not the case currently.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd</span></span><br><span class="line"><span class="comment">         * for more information as all the semantics and arguments have a one to</span></span><br><span class="line"><span class="comment">         * one mapping on this function.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * Atomic drivers should use drm_atomic_helper_dirtyfb() to implement</span></span><br><span class="line"><span class="comment">         * this hook.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * RETURNS:</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * 0 on success or a negative error code on failure.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">int</span> (*dirty)(<span class="keyword">struct</span> drm_framebuffer *framebuffer,</span><br><span class="line">                     <span class="keyword">struct</span> drm_file *file_priv, <span class="type">unsigned</span> flags,</span><br><span class="line">                     <span class="type">unsigned</span> color, <span class="keyword">struct</span> drm_clip_rect *clips,</span><br><span class="line">                     <span class="type">unsigned</span> num_clips);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>其中：</p>
<ul>
<li>destory：清理framebuffer资源的回调函数；</li>
<li>create_handle：创建驱动程序特定缓冲区管理器（GEM或TTM）中与给定文件对象drm_file相关联的缓冲区句柄；</li>
<li>dirty：选的回调函数，用于处理dirty fb IOCTL；</li>
</ul>
<h4 id="1-4-关系图"><a href="#1-4-关系图" class="headerlink" title="1.4 关系图"></a>1.4 关系图</h4><p>为了更加清晰的了解struct drm_framebuffer、struct drm_format_info、struct drm_framebuffer_funcs数据结构的关系，我们绘制了如下关系图：</p>
<p><img src="https://gitee.com/zyly2033/blog-pic/raw/master/202309031515578.svg"></p>

        
      </div>

         
    </div>
    
     
  </div>
  
    
<nav id="article-nav">
  <a class="article-nav-btn left "
    
      href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20plane/"
      title=""
     >
    <i class="fa-solid fa-angle-left"></i>
    <p class="title-text">
      
        (No Title)
        
    </p>
  </a>
  <a class="article-nav-btn right "
    
      href="/blog/2023/09/11/rk3399/Rockchip%20RK3399%20-%20DRM%20crtc/"
      title=""
     >

    <p class="title-text">
      
        (No Title)
        
    </p>
    <i class="fa-solid fa-angle-right"></i>
  </a>
</nav>


  
</article>

 
    </div>
    <div id="footer-wrapper">
      <footer id="footer">
  
  <div id="footer-info" class="inner">
    
    &copy; 2023 Your Name<br>
    Powered by <a href="https://hexo.io/" target="_blank">Hexo</a> & Theme <a target="_blank" rel="noopener" href="https://github.com/saicaca/hexo-theme-vivia">Vivia</a>
  </div>
</footer>

    </div>
    <div class="back-to-top-wrapper">
    <button id="back-to-top-btn" class="back-to-top-btn hide" onclick="topFunction()">
        <i class="fa-solid fa-angle-up"></i>
    </button>
</div>

<script>
    function topFunction() {
        window.scroll({ top: 0, behavior: 'smooth' });
    }
    let btn = document.getElementById('back-to-top-btn');
    function scrollFunction() {
        if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) {
            btn.classList.remove('hide')
        } else {
            btn.classList.add('hide')
        }
    }
    window.onscroll = function() {
        scrollFunction();
    }
</script>

  </div>
  <script src="/blog/js/light-dark-switch.js"></script>
</body>
</html>
